#include "emfdrawablebuilder.h"


EmfDrawableBuilder::EmfDrawableBuilder()
{
}

QMap<QString, Drawable *> EmfDrawableBuilder::build()
{
    QMap<QString, Drawable *> map;


    if(!_model.isNull())
    {
        _model->setFilter(_modelFilter);
        _model->select();

        for(int i=0; i<_model->rowCount(); i++)
        {
            QSqlRecord rec = _model->record(i);
            QString currentId = rec.value("idEmf").toString();

            QVariant x = rec.value("time");
            QVariant y = rec.value("value");

            if(!map.contains(currentId))
            {
                map.insert(currentId, new EmfDrawable);
            }
            ((EmfDrawable*)map[currentId])->setTag(this->_globalId);
            ((EmfDrawable*)map[currentId])->addCoordinates(QPointF(x.toDouble(), y.toDouble()));
        }
    }
    else
    {
        for(int i=0; i<_rowRecord.size(); i++)
        {
            QSqlRecord rec = _rowRecord[i];
            QString currentId = rec.value("idEmf").toString();

            QVariant x = rec.value("time");
            QVariant y = rec.value("value");

            if(!map.contains(currentId))
            {
                map.insert(currentId, new EmfDrawable);
            }
            ((EmfDrawable*)map[currentId])->setTag(this->_globalId);
            ((EmfDrawable*)map[currentId])->addCoordinates(QPointF(x.toDouble(), y.toDouble()));
        }
    }

    return map;
}
